using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Sandia.MVCFramework.Test
{
    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class NUnitTraceListener: CustomTraceListener
    {
        public static bool Called = false;

        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            NUnitTraceListener.Called = true;
            if (data is LogEntry && this.Formatter != null)
            {
                Console.Error.WriteLine(this.Formatter.Format(data as LogEntry));
                Console.Error.WriteLine("\n ");
            }
            else
            {
                Console.Error.WriteLine(data.ToString());
                Console.Error.WriteLine("\n ");
            }
        }

        public override void Write(string message)
        {
            NUnitTraceListener.Called = true;
            Console.Error.Write(message);
        }

        public override void WriteLine(string message)
        {
            NUnitTraceListener.Called = true;
            Console.Error.WriteLine(message);
            Console.Error.WriteLine("\n ");
        }
    }
}
